﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace GrayParrot.Web.Formly
{
    /// <summary>
    /// The Template Options Attribute...
    /// </summary>
    [AttributeUsage(AttributeTargets.Property, Inherited = true, AllowMultiple = false)]
    public abstract class TemplateOptionsAttribute : Attribute
    {
        /// <summary>
        /// Used to add an html label to each field
        /// </summary>
        /// <value>
        /// The label.
        /// </value>
        [JsonProperty(PropertyName = "label")]
        public string Label { get; set; }

        /// <summary>
        /// Used to add the required attribute to a form field.
        /// </summary>
        /// <value>
        ///   <c>true</c> if required; otherwise, <c>false</c>.
        /// </value>
        [JsonProperty(PropertyName = "required")]
        public bool Required { get; set; }

        /// <summary>
        /// used to add the disabled attribute to a form field.
        /// </summary>
        /// <value>
        ///   <c>true</c> if disabled; otherwise, <c>false</c>.
        /// </value>
        [JsonProperty(PropertyName = "disabled")]
        public bool Disabled { get; set; }

        /// <summary>
        /// Used to add placeholder text to some inputs.
        /// </summary>
        /// <value>
        /// The Placeholder.
        /// </value>
        [JsonProperty(PropertyName = "placeholder")]
        public string Placeholder { get; set; }

        /// <summary>
        /// Used to add descriptive text to all inputs.
        /// </summary>
        /// <value>
        /// The description.
        /// </value>
        [JsonProperty(PropertyName = "description")]
        public string Description { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="TemplateOptionsAttribute"/> is hidden.
        /// </summary>
        /// <value>
        ///   <c>true</c> if hidden; otherwise, <c>false</c>.
        /// </value>
        /// <remarks>
        /// Indicates that the field is statically declared as hidden.
        /// It is used when you known that the field is not to be shown
        /// </remarks>
        [JsonProperty(PropertyName = "hidden")]
        public bool Hidden { get; set; }

        /// <summary>
        /// Gets or sets the disable callback.
        /// </summary>
        /// <value>
        /// The disable callback.
        /// </value>
        /// <remarks>
        /// Used to declare a client function that return TRUE if the field is disable.
        /// This callback is used to dinamically enable or disable the field, on the value returned by the callback
        /// </remarks>
        [JsonProperty(PropertyName = "disableCallback")]
        public string DisableCallback { get; set; }

        /// <summary>
        /// Gets or sets the hidden callback.
        /// </summary>
        /// <value>
        /// The hidden callback.
        /// </value>
        /// <remarks>
        /// Used to declare a client function that return TRUE if the field is to be shown.
        /// This callback is used to dinamically hide or shown the field, on the value returned by the callback
        /// </remarks>
        [JsonProperty(PropertyName = "hiddenCallback")]
        public string HiddenCallback { get; set; }

        [JsonProperty(PropertyName = "fieldGroup", DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore)]
        public FieldGroupDetail FieldGroup { get; set; }

        ///// <summary>
        ///// Gets or sets the on change event callback (for select options field)...
        ///// </summary>
        ///// <value>
        ///// The on change.
        ///// </value>
        //[JsonProperty(PropertyName = "onChange")]
        //public string OnChange { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="TemplateOptionsAttribute"/> class.
        /// </summary>
        public TemplateOptionsAttribute()
        {
            this.Required = true;
            this.Disabled = false;
            this.Hidden = false;
            this.FieldGroup = null;
        }
    }
}
